<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Xlore 终端模拟器</title>
    <style>
        :root {
            --primary-color: #00ffd0;
            --background: linear-gradient(45deg, #0a0a0a, #1a1a1a);
            --console-bg: rgba(0, 20, 30, 0.9);
            --error-color: #ff4444;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            background: var(--background);
            color: var(--primary-color);
            font-family: 'Consolas', 'Monaco', 'PingFang SC', 'Microsoft YaHei', monospace;
            line-height: 1.6;
            height: 100vh;
            display: flex;
            flex-direction: column;
            backdrop-filter: blur(5px);
        }

        #console {
            flex: 1;
            padding: 1.5rem;
            overflow-y: auto;
            background: var(--console-bg);
            box-shadow: 0 0 20px rgba(0, 255, 208, 0.1);
        }

        .input-line {
            padding: 1rem;
            background: var(--console-bg);
            border-top: 1px solid rgba(0, 255, 208, 0.1);
            display: flex;
            align-items: center;
            gap: 0.8rem;
        }

        .prompt {
            color: #ff3366;
            font-weight: bold;
            white-space: nowrap;
        }

        .command-input {
            background: transparent;
            border: none;
            color: var(--primary-color);
            font-family: inherit;
            font-size: 1rem;
            width: 100%;
            outline: none;
            caret-color: var(--primary-color);
            transition: all 0.3s ease;
        }

        .command-input:focus {
            box-shadow: 0 2px 0 var(--primary-color);
        }

        .output {
            margin: 1rem 0;
            white-space: pre-wrap;
            word-break: break-word;
        }

        .error {
            color: var(--error-color);
            animation: shake 0.5s;
        }

        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(5px); }
            75% { transform: translateX(-5px); }
        }

        @media (max-width: 768px) {
            #console {
                padding: 1rem;
            }
            
            .input-line {
                padding: 0.8rem;
            }
            
            .prompt {
                font-size: 0.9rem;
            }
            
            .command-input {
                font-size: 0.9rem;
            }
        }
        .root-mode {
            --primary-color: #ff0066;
            --console-bg: rgba(30, 0, 10, 0.9);
        }
        
        .privilege-text {
            color: #ff9900;
            font-weight: bold;
        }

        @keyframes blink {
            50% { opacity: 0; }
        }

        .command-input::after {
            content: "|";
            animation: blink 1s step-end infinite;
        }
    </style>
</head>
<body>
    <div id="console"></div>
    <div class="input-line">
        <span class="prompt" id="prompt">user@xlore:~$</span>
        <input type="text" class="command-input" id="commandInput" autofocus>
    </div>

    <script>
        let privilegeLevel = 0;
        let flagFound = false;
        const baseCommands = {
            'help': {
                desc: '显示可用命令',
                execute: () => Object.keys(commands)
                    .map(cmd => `${cmd.padEnd(10)}${commands[cmd].desc}`)
                    .join('\n')
            },
            'clear': {
                desc: '清空终端',
                execute: () => consoleElement.innerHTML = ''
            },
            'echo': {
                desc: '显示输入文本',
                execute: args => args.join(' ')
            },
            'contact': {
                desc: '显示联系信息',
                execute: () => '开发者: 星络枢(ShloreX)\n博客: https://shlorex.github.io [使用"blog"命令]\n作业信息: https://shloreblog.acmebloe.cn [使用"work"命令]'
            }
        };

        const rootCommands = {
            'flag': {
                desc: '显示比赛flag',
                execute: () => flagFound ? '下一关地址{c2hsb3JlYmxvZy5hY21lYmx1ZS5jbg==}' : '请先使用nmap扫描网络'
            },
            'nmap': {
                desc: '网络扫描工具',
                execute: () => {
                    flagFound = true;
                    return '发现敏感服务: 666/tcp\n隐藏端点: /flag.txt'
                }
            },
            'log': {
                desc: '查看系统日志',
                execute: () => '发现可疑的提权尝试...'
            }
        };

        const commands = { ...baseCommands };
        const consoleElement = document.getElementById('console');
        const commandInput = document.getElementById('commandInput');
        let commandHistory = [];
        let historyPosition = 0;

        commandInput.addEventListener('keyup', (e) => {
            if(e.key === 'Enter') {
                const input = commandInput.value.trim();
                commandHistory.push(input);
                historyPosition = commandHistory.length;
                
                addToConsole(`${document.getElementById('prompt').textContent} ${input}`, 'input');
                
                if (checkPrivilege(input)) {
                    Object.assign(commands, rootCommands);
                    document.body.classList.add('root-mode');
                    addToConsole('特权升级成功！解锁新命令', 'privilege-text');
                }

                const [cmd, ...args] = input.split(' ');
                if (commands[cmd]) {
                    try {
                        const output = commands[cmd].execute(args);
                        output && addToConsole(output);
                    } catch (e) {
                        addToConsole(`执行错误：${e}`, 'error');
                    }
                } else if (cmd === 'blog') {
                    window.open('https://shlorex.github.io', '_blank');
                    addToConsole('正在打开博客...');
                }else if (cmd === 'work') {
                    window.open('https://shloreblog.acmeblue.cn', '_blank');
                    addToConsole('正在打开博客...');
                } else if (cmd === 'forum') {
                    window.open('#', '_blank');
                    addToConsole('正在跳转论坛...');
                } else {
                    addToConsole(`未找到命令：${cmd}`, 'error');
                }
                commandInput.value = '';
            }
        });

        function checkPrivilege(input) {
            if ((input.length > 50 && privilegeLevel === 0) || input === 'sudo CTF@Xlore') {
                privilegeLevel = 1;
                document.getElementById('prompt').textContent = 'xuser@xlore:~#';
                return true;
            }
            return false;
        }

        function addToConsole(text, className = 'output') {
            const div = document.createElement('div');
            div.className = className;
            div.textContent = text;
            consoleElement.appendChild(div);
            consoleElement.scrollTop = consoleElement.scrollHeight;
        }

        addToConsole('Xlore 终端模拟器\n输入 "help" 获取命令列表');
    </script>
</body>
</html>